﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DataTransferObject
{
    /*
     * Chứa danh sách thời gian trống và các methods hỗ trợ cho việc quản lý danh sách này
     */ 
    public class FreeTimeList
    {
        #region Attributes

        /// <summary>
        /// 
        /// </summary>
        private List<FreeTimeBlock> freeTimeBlockList;
        /// <summary>
        /// 
        /// </summary>
        private int currentBlock;
        /// <summary>
        /// 
        /// </summary>
        private int numberOfFreeTimeBlock;

        #endregion

        #region Essential Methods

        /// <summary>
        /// Initializes a new instance of the <see cref="FreeTimeList"/> class.
        /// </summary>
        public FreeTimeList()
        {
            this.freeTimeBlockList = new List<FreeTimeBlock>();
            this.currentBlock = -1;
            this.numberOfFreeTimeBlock = 0;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="FreeTimeList"/> class.
        /// </summary>
        /// <param name="freeTimeBlocks">The free time blocks.</param>
        public FreeTimeList(List<FreeTimeBlock> freeTimeBlocks)
        {
            this.currentBlock = -1;
            this.freeTimeBlockList = freeTimeBlocks;
            this.numberOfFreeTimeBlock = freeTimeBlockList.Count;
        }

        /// <summary>
        /// Adds the free time block to list.
        /// </summary>
        /// <param name="freeTimeBlock">The free time block.</param>
        /// <returns></returns>
        public bool addFreeTimeBlockToList(FreeTimeBlock freeTimeBlock)
        {
            this.freeTimeBlockList.Add(freeTimeBlock);
            if (freeTimeBlockList.Count == numberOfFreeTimeBlock)
            {
                return false;
            }
            else
            {
                numberOfFreeTimeBlock = numberOfFreeTimeBlock + 1;
                return true;
            }
        }


        /// <summary>
        /// Removes the free time block.
        /// </summary>
        /// <param name="index">The index.</param>
        public void removeFreeTimeBlock(int index)
        {
            this.freeTimeBlockList.RemoveAt(index);
        }

        /// <summary>
        /// Fists the block.
        /// </summary>
        /// <returns></returns>
        public FreeTimeBlock fistBlock()
        {
            return (FreeTimeBlock)this.freeTimeBlockList[0];
        }

        /// <summary>
        /// Nexts the block.
        /// </summary>
        /// <returns></returns>
        public FreeTimeBlock nextBlock()
        {
            //currentBlock = (currentBlock == timeBlocks.Count - 1)?(currentBlock = 0):(currentBlock++);
            currentBlock++;
            return (FreeTimeBlock)freeTimeBlockList[currentBlock];
        }

        /// <summary>
        /// Determines whether [is any free block].
        /// </summary>
        /// <returns>
        /// 	<c>true</c> if [is any free block]; otherwise, <c>false</c>.
        /// </returns>
        public bool isAnyFreeBlock()
        {
            return (currentBlock != freeTimeBlockList.Count - 1);
        }

        

        #endregion

        #region Properties

        public List<FreeTimeBlock> FreeTimeBlockList
        {
            get { return freeTimeBlockList; }
            set { this.freeTimeBlockList = value; }
        }

        public int CurrentBlock
        {
            get { return currentBlock; }
            set { this.currentBlock = value; }
        }

        public int NumberOfFreeTimeBlock
        {
            get { return this.numberOfFreeTimeBlock; }
            set { this.numberOfFreeTimeBlock = value; }
        }

        #endregion

        #region bổ sung
        /* @LUÂN
         * CÁC BẠN CÓ THỂ:
         * 1. COMMENT VỀ NHỮNG BỔ SUNG GÓP Ý
         * 2. VIẾT CODE ĐỀ XUẤT TRONG REGION NÀY
         * 
        */


        #endregion
    }
}
